package com.ruoyi.web.controller.outbound;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.outbound.consignment.domain.Consignment;
import com.ruoyi.outbound.consignment.service.IConsignmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发货通知单Controller
 * 
 * @author zzx
 * @date 2024-02-07
 */
@RestController
@RequestMapping("/system/consignment")
public class ConsignmentController extends BaseController
{
    @Autowired
    private IConsignmentService consignmentService;

    /**
     * 查询发货通知单列表
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Consignment consignment)
    {
        startPage();
        List<Consignment> list = consignmentService.selectConsignmentList(consignment);
        return getDataTable(list);
    }

    /**
     * 导出发货通知单列表
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:export')")
    @Log(title = "发货通知单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Consignment consignment)
    {
        List<Consignment> list = consignmentService.selectConsignmentList(consignment);
        ExcelUtil<Consignment> util = new ExcelUtil<Consignment>(Consignment.class);
        util.exportExcel(response, list, "发货通知单数据");
    }

    /**
     * 获取发货通知单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:query')")
    @GetMapping(value = "/{consignmentId}")
    public AjaxResult getInfo(@PathVariable("consignmentId") String consignmentId)
    {
        return success(consignmentService.selectConsignmentByConsignmentId(consignmentId));
    }

    /**
     * 新增发货通知单
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:add')")
    @Log(title = "发货通知单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Consignment consignment)
    {
        return toAjax(consignmentService.insertConsignment(consignment));
    }

    /**
     * 修改发货通知单
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:edit')")
    @Log(title = "发货通知单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Consignment consignment)
    {
        return toAjax(consignmentService.updateConsignment(consignment));
    }

    /**
     * 删除发货通知单
     */
    @PreAuthorize("@ss.hasPermi('c:consignment:remove')")
    @Log(title = "发货通知单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consignmentIds}")
    public AjaxResult remove(@PathVariable String[] consignmentIds)
    {
        return toAjax(consignmentService.deleteConsignmentByConsignmentIds(consignmentIds));
    }
    /**
     * 审核生产工单
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:edit')")
    @Log(title = "发货通知单", businessType = BusinessType.UPDATE)
    @PutMapping("/audit/{consignmentId}")
    public AjaxResult updateAudit(@PathVariable("consignmentId") String consignmentId)
    {
        return consignmentService.updateAudit(consignmentId);
    }
    /**
     * 结案/反结案生产工单
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:edit')")
    @Log(title = "发货通知单", businessType = BusinessType.UPDATE)
    @PutMapping("/close/{consignmentId}")
    public AjaxResult updateClose(@PathVariable("consignmentId") String consignmentId)
    {
        return consignmentService.updateClose(consignmentId);
    }
    /**
     * 数据同步
     */
    @PreAuthorize("@ss.hasPermi('system:consignment:syncData')")
    @Log(title = "发货通知单管理:金蝶同步数据", businessType = BusinessType.UPDATE)
    @PostMapping("/syncData")
    public AjaxResult syncData()
    {
        return consignmentService.syncData("consignment");
    }
}


